Skip to content

Add Kitty Keyboard Protocol support (Phase 1 + Phase 2 start) - #4810

Merged
tig merged 50 commits into
tui-cs:v2_developfrom
tig:feature/kitty
Mar 9, 2026
Merged

Add Kitty Keyboard Protocol support (Phase 1 + Phase 2 start)#4810
tig merged 50 commits into
tui-cs:v2_developfrom
tig:feature/kitty

Conversation

@tig

@tig tig commented Mar 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Phase 1 complete: Kitty keyboard protocol detection, enable/disable lifecycle, CSI u parser, and compatibility mapping into the current Key model
  • Phase 2 started: Plan updated with detailed implementation steps for rich keyboard event model (KeyUp, KeyEventType, standalone modifier events)
  • Merged latest v2_develop and resolved all conflicts

Relates to #4809

What's included

Phase 1 — Compatibility plumbing

  • Kitty protocol query/enable/disable constants in EscSeqUtils
  • KittyKeyboardProtocolDetector with structured results
  • Startup detection wiring in MainLoopCoordinator
  • AnsiOutput enable/disable lifecycle with degraded mode safety
  • KittyKeyboardPattern parser (checked before generic CSI patterns)
  • Compatibility mapping: printable keys, modifiers, navigation, editing, function keys through F24
  • Comprehensive tests: detector, parser, input, lifecycle, and startup

Merge resolution

  • Resolved 8 merge conflicts from v2_develop integration
  • Fixed Trace ambiguity (System.Diagnostics.Trace vs Terminal.Gui.Tracing.Trace)
  • Adopted v2_develop's using Terminal.Gui.Tracing pattern and primary constructor style

Test plan

  • dotnet build --no-restore passes
  • dotnet test --project Tests/UnitTestsParallelizable --no-build — all pass
  • dotnet test --project Tests/UnitTests --no-build — all pass
  • Manual testing with kitty-capable terminal (Windows Terminal Preview 1.25+)

🤖 Generated with Claude Code

tig added 13 commits March 5, 2026 11:41
Refactor terminal attachment checks into Driver.IsAttachedToTerminal, which now handles platform-specific logic and honors the DisableRealDriverIO environment variable for test environments. Updated all drivers to use this unified method, and simplified AnsiTerminalHelper to delegate to it. Moved relevant P/Invoke code to Driver. Added comprehensive unit tests for all drivers and the environment variable gating. Introduced test.runsettings and Directory.Build.props changes to ensure DisableRealDriverIO is set during test runs, improving testability and consistency of degraded mode detection.
- Reformat method calls and declarations for readability
- Use C# pattern matching and switch expressions
- Refactor OutputBase properties to auto-properties
- Convert trivial methods to expression-bodied members
- Fix logic in OutputBase.Write, UnixInput init, and WindowsOutput error handling
- Remove AnsiTerminalHelper.IsAttachedToTerminal and related test
- Use explicit types for clarity
- Reformat and clarify P/Invoke signatures
- Update .DotSettings and documentation comments
- Improve maintainability and correctness throughout drivers
@tig
tig marked this pull request as draft March 8, 2026 20:41
tig and others added 15 commits March 8, 2026 14:59
Add IsAttachedToTerminal to OutputBase and update all output drivers (AnsiOutput, NetOutput, UnixOutput, WindowsOutput) to check this property before performing terminal I/O. When not attached to a real terminal, output methods now return early, perform no-ops, or return default values. Constructors log lifecycle messages if no terminal is attached. Tests updated to verify no escape sequences or state changes occur in these scenarios. This prevents errors and unwanted output in redirected or non-interactive environments.
Move IsAttachedToTerminal checks after base logic in Output classes to ensure base behavior is always executed. Streamline and centralize terminal checks, reduce code duplication, and improve consistency across AnsiOutput, NetOutput, UnixOutput, and WindowsOutput. Adjust platform-specific logic and early returns for better maintainability and correct output buffer handling.
Centralize IsAttachedToTerminal logic in InputImpl<T> and update all input classes (AnsiInput, NetInput, UnixInput, WindowsInput) to use it for degraded mode detection and logging. Simplify AnsiOutput by removing redundant terminal checks and updating Kitty keyboard methods. Refactor MainLoopCoordinatorTests for modern C# syntax, restoring and improving Kitty protocol and error handling tests. Improves clarity, maintainability, and test reliability.
Refactor terminal attachment checks into Driver.IsAttachedToTerminal, which now handles platform-specific logic and honors the DisableRealDriverIO environment variable for test environments. Updated all drivers to use this unified method, and simplified AnsiTerminalHelper to delegate to it. Moved relevant P/Invoke code to Driver. Added comprehensive unit tests for all drivers and the environment variable gating. Introduced test.runsettings and Directory.Build.props changes to ensure DisableRealDriverIO is set during test runs, improving testability and consistency of degraded mode detection.
- Reformat method calls and declarations for readability
- Use C# pattern matching and switch expressions
- Refactor OutputBase properties to auto-properties
- Convert trivial methods to expression-bodied members
- Fix logic in OutputBase.Write, UnixInput init, and WindowsOutput error handling
- Remove AnsiTerminalHelper.IsAttachedToTerminal and related test
- Use explicit types for clarity
- Reformat and clarify P/Invoke signatures
- Update .DotSettings and documentation comments
- Improve maintainability and correctness throughout drivers
Add IsAttachedToTerminal to OutputBase and update all output drivers (AnsiOutput, NetOutput, UnixOutput, WindowsOutput) to check this property before performing terminal I/O. When not attached to a real terminal, output methods now return early, perform no-ops, or return default values. Constructors log lifecycle messages if no terminal is attached. Tests updated to verify no escape sequences or state changes occur in these scenarios. This prevents errors and unwanted output in redirected or non-interactive environments.
Move IsAttachedToTerminal checks after base logic in Output classes to ensure base behavior is always executed. Streamline and centralize terminal checks, reduce code duplication, and improve consistency across AnsiOutput, NetOutput, UnixOutput, and WindowsOutput. Adjust platform-specific logic and early returns for better maintainability and correct output buffer handling.
Centralize IsAttachedToTerminal logic in InputImpl<T> and update all input classes (AnsiInput, NetInput, UnixInput, WindowsInput) to use it for degraded mode detection and logging. Simplify AnsiOutput by removing redundant terminal checks and updating Kitty keyboard methods. Refactor MainLoopCoordinatorTests for modern C# syntax, restoring and improving Kitty protocol and error handling tests. Improves clarity, maintainability, and test reliability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Moved and duplicated tests for DisableRealDriverIO env var and Driver.IsAttachedToTerminal from DriverTests to IntegrationTests. Also refactored test output usage to use the output parameter directly. This ensures environment variable handling is verified in both test contexts.
# Conflicts:
#	Terminal.Gui/Drivers/AnsiDriver/AnsiInput.cs
#	Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs
#	Terminal.Gui/Drivers/DotNetDriver/NetInput.cs
#	Terminal.Gui/Drivers/UnixDriver/UnixInput.cs
#	Terminal.Gui/Drivers/WindowsDriver/WindowsInput.cs
#	Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs
#	Tests/UnitTests/Application/MainLoopCoordinatorTests.cs
#	Tests/UnitTestsParallelizable/Application/MainLoopCoordinatorTests.cs
#	Tests/UnitTestsParallelizable/Drivers/Ansi/AnsiTerminalHelperTests.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tig and others added 13 commits March 9, 2026 08:40
Refactored tracing calls in input classes to remove unnecessary string interpolation and ensure consistent usage of Trace.Lifecycle. Added early return in AnsiOutput for degraded platforms. Simplified window size comparison in WindowsOutput. Cleaned up imports and removed redundant code in test files, including refactoring test output usage for clarity.
Remove commented-out logging/tracing statements from AnsiInput, AnsiOutput, and WindowsOutput for cleaner code. Refactor AnsiOutput to use an auto-property for KittyKeyboardEnabledFlags and update related logic. Add a descriptive trace message to AnsiOutput.Dispose(). Replace commented exception in WindowsOutput with a trace log on resize failure. Minor doc and formatting improvements in NetInput.
AnsiOutput.EnableKittyKeyboard now skips enablement when the platform is Degraded, making it a no-op in such environments. Updated related test to focus on detection rather than enable/disable, renamed the test for clarity, and adjusted assertions to match the new behavior. Removed checks for escape sequences that are not emitted in degraded mode.
Adds detailed implementation steps for Phase 2 (Rich Keyboard Event Model)
including Key.EventType, KeyUp pipeline, Windows/kitty driver integration,
standalone modifier events, and view-level keyboard updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tig tig changed the title Phase 1 of Fixing #4890 - Adds Kitty Keyboard Support Add Kitty Keyboard Protocol support (Phase 1 + Phase 2 start) Mar 9, 2026
@tig
tig merged commit d67adcc into tui-cs:v2_develop Mar 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants